package com.fds.app.comm.util;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BeanDebugUtil {
	private static Logger logger =  LoggerFactory.getLogger(BeanDebugUtil.class);
	
	public static void showBeanInfo(Object object) {
		
		try {
			BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass());
			
			PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
			
			for(PropertyDescriptor pd : pds) {
				logger.info(">>> {} [{}]", String.format("[%20s] [%-20s]", pd.getPropertyType().getName(), pd.getName())
						                 , pd.getReadMethod().invoke(object));
			}
			
		} catch (IntrospectionException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		
	}
}
